package com.airnews.ticket.ui;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.airnews.ticket.R;
import com.airnews.ticket.util.NetUtils;

/**
 * 
 * Activity基类，实现页面公共视图设置和初始化工作
 * 
 * 注意：基础此累需先调用 	setContentView(...) 
 * 后调用 				super.onCreate(...)
 */
public class BaseActivity extends Activity {

	protected TextView title_bar;
	
	protected ProgressDialog progressDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setupView();
		
		if (!NetUtils.httpTest(this)) {
			return;
		}
	}

	
	private void setupView() {
		title_bar = (TextView)findViewById(R.id.title_bar);
	}
	
	
	/**
	 * 设置标题栏文本
	 * @param title
	 */
	protected void setTitleBar(String title){
		if(title_bar != null){
			title_bar.setText(title);
		}
	}
	
	protected void setTitleBar(int titleId){
		if(title_bar != null){
			title_bar.setText(getString(titleId));
		}
	}
	
	protected void showDatePickerDialog(OnDateSetListener dateSetListener, 
			int year, int month, int day){
		new DatePickerDialog(this, dateSetListener, 
				year, month, day).show();
	}


	@Override
	public void startActivity(Intent intent) {
		super.startActivity(intent);
		overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);
	}
	
	
	protected void showProgressDialog(String msg, boolean cancelable){
		progressDialog = ProgressDialog.show(this, null, msg, true, cancelable);
	}
	
	protected void dismissProgressDialog(){
		if(progressDialog != null && progressDialog.isShowing()){
			progressDialog.dismiss();
		}
	}
	

}
